package com.cellngine;

import java.io.IOException;

public class Cellngine
{
	private static String	path;
	private static Logger	file_logger, console_logger;
	private static long		unid	= 0;					//the unique id for every object is generated from this variable
															
	static
	{
		try
		{
			path = new java.io.File(".").getCanonicalPath() + "/";
		}
		catch (final IOException e)
		{
		}
		
		console_logger = new Logger();
		file_logger = new Logger("logs/console_", true);
	}
	
	/**
	 * Calls the <code>Logger.log</code> method on the file and console logger, if they're
	 * available.
	 * 
	 * @param o
	 *            A valid <code>String</code> or something that can be converted to a
	 *            <code>String</code> object.
	 *            Please note that it is valid (and even encouraged!) to pass <code>Exception</code>
	 *            objects to this method.
	 * @param type
	 *            A valid <code>Constants.log_type</code> enumeration indicating the kind of message
	 *            that is to be output.
	 */
	public static void log(final Object o, final Constants.log_type type)
	{
		if (file_logger != null)
		{
			file_logger.log(o, type);
		}
		
		if (console_logger != null)
		{
			console_logger.log(o, type);
		}
	}
	
	public static String getVersion()
	{
		String v = "v" + Constants.VERSION_MAJOR + "." + Constants.VERSION_MINOR;
		if (Constants.VERSION_REVISION != null)
		{
			v += " (rev. " + Constants.VERSION_REVISION + ")";
		}
		
		return v;
	}
	
	public static Logger getConsoleLog()
	{
		return console_logger;
	}
	
	public static Logger getFileLog()
	{
		return file_logger;
	}
	
	public static String getPath()
	{
		return path;
	}
	
	public static long newUNID()
	{
		if (unid == 0)
		{
			unid = JO.getTimestamp();
		}
		
		return ++unid;
	}
}